package com.qd.panda.shop.product;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdqidi.util.page.PageUtil;
import com.qd.common.panda.domain.entity.shop.product.ProductDTO;
import com.qd.panda.service.shop.product.ProductService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * APP_商品信息
 *
 * @author sjk
 */
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/app/product/")
@Slf4j
public class AppProductController {
    private final ProductService productService;

    /**
     * 获取商品信息
     *
     * @param id 主键
     * @return 记录
     */
    @GetMapping(value = "/getById")
    public ProductDTO getById(@Validated @NotBlank(message = "ID不能为空") String id) {
        return productService.getByIdDto(id);
    }

    /**
     * 商品信息列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/page")
    public IPage<ProductDTO> page(ProductDTO dto) {
        dto.setState(0);
        return productService.page(PageUtil.buildPage(dto), dto);
    }
}